package com.youth.vod.controller;

import com.youth.commonutils.R;
import com.youth.vod.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;

@Api(description = "视频相关操作")
@RestController
@RequestMapping("/eduvod/video")
//使用nginx是需要使用@CrossOrigin解决跨域问题的，现在使用gateway网关替代
public class VodController {

    @Autowired
    private VodService vodService;

    @PostMapping("uploadVideo")
    public R uploadVideo(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file) {
        /*返回videoId，用于填充video地址到数据库中*/
        String videoId = vodService.uploadVideo(file);
        String originalFilename = file.getOriginalFilename();
        return R.ok().message("视频上传成功").data("videoId", videoId).data("fileName", originalFilename);
    }

    @DeleteMapping("removeAliVideo/{videoId}")
    public R revmoveVideoSource(@PathVariable("videoId") String videoSourceId) {
        return vodService.removeVideo(videoSourceId);
    }

}